#include <fstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <boost/program_options.hpp>
#include <string>
#include <math.h>
#include "get_arg.h"


// link with -lboost_filesystem-gcc -lboost_program_options-gcc  -lboost_regex-gcc
// program_options_helper.cpp

// my functions
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <matrix_formats.h>
#include <print_error.h>
#include <program_options_helper.h>

using std::string;
using std::cerr;
using namespace program_options_helper;
namespace po = boost::program_options_lg;



bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	// mandatory arguments
	string matrix_file_name;
	po::options_description mandatory_args("Mandatory Arguments");
	mandatory_args.add_options()
	("x_taxon,x", po::value<string>(&args.taxon1)->set_name("REGEX"),
									"Regular expression to identify members of the first taxon.")
	("y_taxon,y", po::value<string>(&args.taxon1)->set_name("REGEX"),
									"Regular expression to identify members of the second taxon.");



	// optional arguments
	char input_format;
	args.optional_args.add_options()
	("input_format,i", po::value<char>(&input_format)->default_value('p')->set_name("FORMAT"),
									"Input FORMAT is binary ('b'), pairs ('p'), "
									"square ('s') or lower triangular ('l') .")
	("header,H",				"Add column headers to identify output.");

	args.add_std_options();
	po::options_description all_args("");
	all_args.add(args.optional_args);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.0\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"Initial version\n"
//			"\tv 1.1\1"
//			"01-02-2005\1"
//			"Split programme so that vanilla version does not do anything with matrices.\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
		"Takes a distance matrix from STDIN "
		"and divides the data up into relationships between two groups (taxon x and y) "
		"identified from supplied regular expressions. \n"
		"The distance between a member and "
		"its closest relative from the other taxon is printed via STDOUT."
		"Also printed out are the number of member from the same taxon group which are "
		"more closely related than this and the closest member of the same group.\n\n";
		print_usage(cerr, string(*argv), "[OPTIONS] < MATRIX_FILE",
							all_args, exe_description, 80);
		return false;
	}

	args.header						= vm.count("header");


	select_matrix_file_format(input_format, args.input_format, "input format");

	args.open_err_log();
	return true;
}









